#define _CRT_SECURE_NO_WARNINGS 1
class KthLargest {
public:
    priority_queue<int, vector<int>, greater<int>> pq;
    int _k;
    KthLargest(int k, vector<int>& nums) {
        _k = k;
        for (auto i : nums)
        {
            pq.push(i);
            if (pq.size() > k) pq.pop();
        }
    }

    int add(int val) {
        if (pq.size() < _k) pq.push(val);
        else if (val > pq.top())
        {
            pq.pop();
            pq.push(val);
        }
        return pq.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */